package com.dongdong.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.domain.Result;
import com.dongdong.em.ResultEnum;
import com.dongdong.pojo.TbItemCat;
import com.dongdong.pojo.TbSpecificationOption;
import com.dongdong.pojo.TbTypeTemplate;
import com.dongdong.service.TbItemCatService;
import com.dongdong.service.TbSpecificationService;
import com.dongdong.service.TbTypeTemplateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@RequestMapping("tbItemCatController")
@Controller
public class TbItemCatController {
   @Reference
   private TbItemCatService tbItemCatService;
    @Reference
    private TbTypeTemplateService tbTypeTemplateService;
    @RequestMapping("getShow")
    public String getShow(){
        return "/admin/item_cat";
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public Result getInfo(Long id){
        if (id == null || id.equals("undefined")){
            id = 0L;
        }
        List<TbItemCat> tree = tbItemCatService.getTree(id);
        if (tree.size()==0){
            return Result.buildResult(ResultEnum.ERROR).setData(id);
        }

        return Result.buildResult(ResultEnum.SUCCESS).setData(tree);
    }

    @RequestMapping("getShowId")
    @ResponseBody
    public Result getShowId(){
       List<TbTypeTemplate> list =  tbTypeTemplateService.getShowId();
      return   Result.buildResult(ResultEnum.SUCCESS).setData(list);
    }
    @RequestMapping("save")
    @ResponseBody
    public Result save(TbItemCat tbItemCat){
        tbItemCatService.save(tbItemCat);
        return   Result.buildResult(ResultEnum.SUCCESS);
    }
    @RequestMapping("toUpdate")
    @ResponseBody
    public Result toUpdate(Long id){

       TbItemCat tbItemCat =  tbItemCatService.toUpdate(id);
        return   Result.buildResult(ResultEnum.SUCCESS).setData(tbItemCat);
    }
    @RequestMapping("update")
    @ResponseBody
    public Result toUpdate(TbItemCat tbItemCat){

          tbItemCatService.update(tbItemCat);
        return   Result.buildResult(ResultEnum.SUCCESS);
    }
    @RequestMapping("deleteAll")
    @ResponseBody
    public Result deleteAll(@RequestParam("ids[]")Long[] ids){
        tbItemCatService.deleteAll(ids);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

}
